<!--
 * @Descripttion: 支付完成页，配置引导加群组件
 * @version: 
 * @Author: zongxinliu
 * @Date: 2021-07-26 16:34:47
 * @LastEditors: zongxinliu
 * @LastEditTime: 2021-08-26 16:21:56
-->
<template>
  <div
    class="guide-container"
    v-if="leadGroup.qr_code && !orderInfo.is_buy_gift"
  >
      <section
        class="guide-popup-section"
        :style="
          leadGroup.description || leadGroup.title
            ? { paddingTop: '12px' }
            : { paddingTop: '20px' }
        "
      >
        <h3 class="lineBreak" v-if="leadGroup.description">
          {{ leadGroup.description }}
        </h3>
        <p class="lineBreak" v-if="leadGroup.title">{{ leadGroup.title }}</p>
        <div>
          <img :src="leadGroup.qr_code" alt="" />
          <span>{{ t('lead_group_guide_tip') }}</span>
        </div>
      </section>
  </div>
</template>

<script>
import * as api from "./api";
import { Button } from "vant";
import locale from '../../../../mixins/locale'

export default {
  name: "LeadGroup",
  components: {
    [Button.name]: Button,
  },
  mixins: [locale],
  props: {
    orderInfo: {
      type: Object,
      default: () => {},
    },
    isCart: {
      default: "",
    },
    isAlive: {
      type: Number,
      default: 0,
    },
  },
  data() {
    return {
      showPopup: true, // 是否主动弹出二维码弹窗
      leadGroup: {
		qr_code: "",
        description: "",
        title: "",
        subscribe: false,
      },
    };
  },
  created() {
    if (this.isAlive === 1) {
      api.changealivePrefix("/_alive");
    } else {
      api.changealivePrefix("");
    }
    this.loadData();
  },
  watch: {
    orderInfo: {
      handler: function(val, oldVal) {
        this.loadData();
        if (this.isAlive === 1) {
          api.changealivePrefix("/_alive");
        } else {
          api.changealivePrefix("");
        }
      },
      deep: true,
    },
  },
  methods: {
    // 请求引导入群的数据
    async loadData() {
      const { spu_id, product_id, resource_type } = this.orderInfo;
      const params = {
        guidePageType: 1,
        spuId: spu_id,
        resourceId: product_id,
        resourceType: resource_type,
      };
      const result = this.isCart
        ? await api.getCartLeadGroup()
        : await api.getLeadGroup(params);
      this.leadGroup = result.data;
    },
    open() {
      // TODO：埋点，直播当页支付暂不抽取
      // 神策上报：点击立即扫码
      // sensorsTrackButton({
      //   page_id: 'c***xh541',
      //   goods_id: this.$store.state.pay_complete.orderInfo.spu_id,
      //   spu_type: this.$store.state.goods_detail.baseInfo.spu_type,
      //   page_button: '立即扫码',
      // });
      this.showPopup = true;
      this.$emit("open");
    },
    close() {
      this.showPopup = false;
      this.$emit("close");
    },
  },
};
</script>

<style lang="scss" scoped>
.guide-container {
  width: 7.5rem;
  margin: 0 auto;
  position: relative;
  text-align: center;
  .guide-section {
    box-sizing: border-box;
    width: 6.86rem;
    height: 0.96rem;
    margin: 0 auto;
    padding: 0.24rem 0.32rem;
    display: flex;
    justify-content: space-between;
    font-size: 0.28rem;
    border-radius: 0.16rem;
    background-color: #fff;
    border: 1px solid #cccccc !important;
    border-color: #cccccc !important;
    > .guide-desc {
      display: flex;
      align-items: center;
      img {
        width: 0.48rem;
        height: 0.48rem;
        margin-right: 0.16rem;
      }
      span {
        font-size: 0.28rem;
        color: #333;
      }
    }
    > .van-button {
      height: 0.48rem;
      line-height: 0.28rem;
      padding: 0.1rem 0.24rem;
      font-size: 0.2rem;
    }
    .scan {
      font-size: 0.24rem;
      line-height: 0.48rem;
      height: 0.48rem;
      border-radius: 20px;
      color: #ff781f;
      padding: 0 0.24rem;
      border: 1px solid #ff781f;
    }
  }
  ::v-deep .van-overlay {
    width: 7.5rem;
    left: 50%;
    margin-left: -3.75rem;
  }

    .guide-popup-section {
      padding: 0 0.4rem 0.32rem;
      text-align: center;
      > h3 {
        max-width: 6.7rem;
        margin: 0 0 0.16rem 0;
        line-height: 0.44rem;
        font-size: 0.32rem;
        color: #333;
      }
      > p {
        max-width: 6.7rem;
        margin-bottom: 0.08rem;
        line-height: 0.4rem;
        font-size: 0.28rem;
        color: #333;
      }
      > div {
        > img {
          display: block;
          width: 3.2rem;
          height: 3.2rem;
          margin: 0 auto 0.16rem;
        }
        > span {
          line-height: 0.36rem;
          font-size: 0.24rem;
          color: #999;
        }
      }
      .van-button {
        width: 6.72rem;
        height: 0.8rem;
        font-size: 0.28rem;
        font-weight: 500;
        line-height: 0.8rem;
        border: none;
      }
      .pingtuan-bg {
        background: linear-gradient(
          90deg,
          rgba(255, 73, 83, 1),
          rgba(255, 101, 77, 1),
          rgba(255, 129, 71, 1)
        ) !important;
      }
    }
  }

.lineBreak {
  display: -webkit-box;
  text-overflow: ellipsis;
  word-break: break-all;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  user-select: none;
}
</style>
